package com.klaus.ohMySpace.service.Impl;

import com.klaus.ohMySpace.dao.AdminDao;
import com.klaus.ohMySpace.dao.BaseDao;
import com.klaus.ohMySpace.entity.Admin;
import com.klaus.ohMySpace.service.AdminService;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Mklaus on 15/7/23.
 */
@Service("adminServiceImpl")
public class AdminServiceImpl extends BaseServiceImpl<Admin> implements AdminService {

    @Autowired
    private AdminDao adminDaoImpl;

    @Override
    public BaseDao getBaseDao() {
        return this.adminDaoImpl;
    }

    @Override
    public Admin login(Admin admin) {
        DetachedCriteria dc = DetachedCriteria.forClass(Admin.class);
        dc.add(Restrictions.eq("adminName",admin.getAdminName())).add(Restrictions.eq("password",admin.getPassword()));
        List<Admin> list = adminDaoImpl.search(dc);
        if (list.size() > 0){
            return list.get(0);
        }

        return null;
    }
}
